function RM_applyStyle(input, style){
    input.style.backgroundColor = style.backgroundColor;
    input.style.color = style.color;
}

function RM_hideDefault(selectedInput){
    if (selectedInput.value == RM_viewRenderFormat) {
        RM_applyStyle(selectedInput, RM_normalStyle);
        selectedInput.value = '';
    }
}

function RM_submitSearch() {

    var startdate_field = document.getElementById('RM_module_startdatetime');
    var enddate_field = document.getElementById('RM_module_enddatetime');
    var startdate_field_hidden = document.getElementById('RM_module_startdatetime_hidden');
    var enddate_field_hidden = document.getElementById('RM_module_enddatetime_hidden');

    //If both start and end date sets to empty strings or set to default template values
    if ((startdate_field.value === '' || startdate_field.value == RM_lng_Format) &&
        (enddate_field.value === '' || enddate_field.value == RM_lng_Format)) {

        startdate_field_hidden.value = '';
        enddate_field_hidden.value = '';
        document.getElementById('RM_module_Search').submit();
        return true;
    }

    //If stardate is empty
    if ((startdate_field.value === '' || startdate_field.value == RM_lng_Format)){
        RM_applyStyle(startdate_field, RM_errorStyle);
        return false;
    }

    //If enddate is empty
    if (enddate_field.value === '' || enddate_field.value == RM_lng_Format) {
        RM_applyStyle(enddate_field, RM_errorStyle);
        return false;
    }

    var startDateParts = startdate_field.value.split("/");
    var endDateParts = enddate_field.value.split("/");
    var startDate, endDate;

    if (RM_lng_Format=="dd/mm/yyyy"){
        startDate = new Date(startDateParts[2],startDateParts[1],startDateParts[0]);
        endDate = new Date(endDateParts[2],endDateParts[1],endDateParts[0]);
    } else {
        startDate = new Date(startDateParts[2],startDateParts[0],startDateParts[1]);
        endDate = new Date(endDateParts[2],endDateParts[0],endDateParts[1]);
    }

    if (startDate.getTime() > endDate.getTime()) {
        RM_applyStyle(enddate_field, RM_errorStyle);
        return false;
    }

    // if it gets this far it's ok
    startdate_field_hidden.value = startDate.getFullYear() + "-" + startDate.getMonth() + "-" + startDate.getDate();
    enddate_field_hidden.value = endDate.getFullYear() + "-" + endDate.getMonth() + "-" + endDate.getDate();
    document.getElementById('RM_module_Search').submit();

    return true;
}

function RM_Search_Copy_Start_to_End() {

    var startdate_field = document.getElementById('RM_module_startdatetime');
    var enddate_field = document.getElementById('RM_module_enddatetime');

    enddate_field.value = startdate_field.value;
}